import 'package:flutter/cupertino.dart';
import 'package:flutter_app/bean/list_problem_collect_entity.dart';
import 'package:flutter_app/network/Api.dart';
import 'package:flutter_app/network/ResultData.dart';
import 'package:flutter_app/utils/toast_utils.dart';

/**
 * 采集列表
 */
///
class CollectListModel extends ChangeNotifier {
  
  ListProblemCollectEntity? listProblemCollectEntity;

  /// 获取任务采集列表
  Future<ListProblemCollectEntity?> postListProblemCollect(int currentPage, String page) async {
    Map<String, dynamic> param = {
      "currentPage": currentPage,
      'pageSize': 15,
      'param': page
    };
    ResultData resultData = await Api.postListProblemCollect(param);
    if (resultData.isSuccess) {
      if (currentPage == 1) {
        listProblemCollectEntity = ListProblemCollectEntity.fromJson(resultData.data['data']);
      } else if (currentPage > 1) {
        listProblemCollectEntity!.content!.addAll(ListProblemCollectEntity.fromJson(resultData.data['data']).content!);
      }
      notifyListeners();
    } else {
      toast.show(resultData.data["message"]);
    }
    return listProblemCollectEntity;
  }


  /// bus 更新数据
  // String groupId; // 小组id 用来判断是哪一条数据
  // String taskStatus; // 任务状态 用来显示
  // String memberStatus; // 自身状态0未上传1待确认2已确认
  // String totalProblem; // 上报问题数量
  void upProblemCollectData(String groupId, String taskStatus, String memberStatus, String totalProblem){
    listProblemCollectEntity!.content!.forEach((element) {
      if (element.groupId == groupId) {
        element.taskStatus = taskStatus;
        element.memberStatus = memberStatus;
        element.totalProblem = totalProblem;
        notifyListeners();
      }
    });
  }
}
